import request from "@baige/request"
import xml from "../tools/xml"

// 搜索腾讯软件中心的链接
export default async function(name:string){
    let data:any = await request.get("https://s.pcmgr.qq.com/tapi/web/searchcgi.php",{
        type:"search",
        callback:"searchCallback",
        keyword:name,
        page:1,
        pernum:10,
        more:0
    })
    let searchCallback = (a:any)=>a;
    data = eval(data);
    if(data.code === 0){
        // 获取正常
        data.list = data.list.map(e=>{
            // 下载地址
            e.url = xml.getItem(e.xmlInfo,"url").match(/http.*(?=]])/)?.[0];
            // 软件文件名称
            e.name = xml.getItem(e.xmlInfo,"filename");
            // 软件大小
            e.size = xml.getItem(e.xmlInfo,"filesize");
            // 软件更新时间
            e.time = xml.getItem(e.xmlInfo,"publishdate");
            // 软件版本好号
            e.version = xml.getItem(e.xmlInfo,"versionname");
            // 介绍
            e.message = xml.getItem(e.xmlInfo,"feature").match(/(?<=CDATA\[).*(?=]])/)?.[0];
            delete e.xmlInfo
            return e
        })
    }
    return data
}




















`
    <soft id="1310" ostype="248" osbit="3">
        <displayname>
            <![CDATA[Java Runtime Environment]]>
        </displayname>
        <installscriptenable>0</installscriptenable>
        <smartinstallflag>0</smartinstallflag>
        <cmdlineformat>0</cmdlineformat>
        <cmdlineparam>
            <![CDATA[0]]>
        </cmdlineparam>
        <cookie>
            <![CDATA[]]>
        </cookie>
        <default>1</default>
        <httpspeed>50</httpspeed>
        <logopackid>1</logopackid>
        <maxthreadnum>5</maxthreadnum>
        <p2pdownloadspeed>0</p2pdownloadspeed>
        <p2puploadspeed>0</p2puploadspeed>
        <password></password>
        <referer>
            <![CDATA[]]>
        </referer>
        <speedthreshold>80</speedthreshold>
        <timestamp>1366167903</timestamp>
        <username></username>
        <filename>jre-8u291-windows-i586.exe</filename>
        <filesize>73715464</filesize>
        <hash>394f25c742f46563ac2cf482f07368ac</hash>
        <url>
            <![CDATA[http://dl.softmgr.qq.com/original/Development/jre-8u291-windows-i586.exe]]>       
        </url>
        <publishdate>2021-04-20</publishdate>
        <versionname>8.0.2910.10</versionname>
        <destversion>0.0.0.0-0.0.0.0</destversion>
        <nickversion></nickversion>
        <whatsnew>
            <![CDATA[1.优化了相关功能。]]>
        </whatsnew>
        <whatsnewfeature>
            <![CDATA[优化了相关功能]]>
        </whatsnewfeature>
        <stable>1</stable>
        <free>0</free>
        <plugin>0</plugin>
        <plugininfo>
            <![CDATA[]]>
        </plugininfo>
        <https>
            <![CDATA[https://dl.softmgr.qq.com/original/Development/jre-8u291-windows-i586.exe]]>      
        </https>
        <feature>
            <![CDATA[一款编程语言和计算平台软件]]>
        </feature>
        <logo>jre.png</logo>
        <logo48>1310_48_1453446019.png</logo48>
        <point>82</point>
        <upgradepercent>14</upgradepercent>
    </soft>
`